package org.lgiavedoni.android.franq.core.place.dao;

import java.util.List;

import org.lgiavedoni.android.franq.core.bean.WifiNetwork;
import org.lgiavedoni.android.franq.core.dao.AbstractDAO;
import org.lgiavedoni.android.franq.core.place.Place;
import org.lgiavedoni.android.franq.util.collection.CollectionUtils;
import org.lgiavedoni.android.franq.util.place.PlaceUtil;

import android.telephony.gsm.GsmCellLocation;

public class PlaceDAO extends AbstractDAO<Place> {

	public static final PlaceDAO inst = new PlaceDAO();

	public Place getByLatLong(double latitude, double longitude) {
		for (Place place : getAll()) {
			if (PlaceUtil.areTheSamePlace(place, new Place(latitude, longitude))) {
				return place;
			}
		}
		return null;
	}

	public Place getByGSMCell(GsmCellLocation cellLocation) {
		if (cellLocation == null)
			return null;
		for (Place place : getAll()) {
			if (cellLocation.equals(place.getCellLocation())) {
				return place;
			}
		}
		return null;
	}

	public Place getByNetworks(List<WifiNetwork> networks) {
		for (Place place : getAll()) {
			if (CollectionUtils.cointansAny(networks, place.getNetworks())) {
				return place;
			}
		}
		return null;
	}

	@Override
	public Class getObjectClass() {
		return Place.class;
	}
}
